package com.hx.xiao.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hx.xiao.entity.Su;
import com.hx.xiao.mapper.SuMapper;
import com.hx.xiao.service.ISuService;
import com.hx.xiao.utils.GetDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SuServiceImpl extends ServiceImpl<SuMapper, Su> implements ISuService {

    @Autowired
    private SuMapper suMapper;



    @Override
    public int addSu(Su su) {
        su.setHtime(GetDate.getTime());
        return suMapper.insert(su);
    }

    @Override
    public int delSu(Integer uid, Integer xid) {
        LambdaQueryWrapper<Su> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Su::getUid,uid);
        queryWrapper.eq(Su::getCollect,xid);
        return suMapper.delete(queryWrapper);
    }

    @Override
    public Su selectSu(Integer uid, Integer xid) {
        LambdaQueryWrapper<Su> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Su::getUid,uid);
        queryWrapper.eq(Su::getCollect,xid);
        return suMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Map> findById(Integer id) {
        return suMapper.findById(id);
    }

    @Override
    public List<Map> findtop10(Integer hid) {
        return suMapper.findtop10(hid);
    }


}
